let radius = 500;
const gpu = !true;
const combiner = new ImageCombiner.PNG(radius * 2, radius, {
  gpu,
  filterType: 2,
  textInfo:"this is from chzh"
});
const c1 = document.getElementById("c1");
const c2 = document.getElementById("c2");

c2.width = c1.width = radius;
c2.height = c1.height = radius;

const ctx1 = c1.getContext("2d");
const ctx2 = c2.getContext("2d");

function loadImg(url) {
  return new Promise((resolve) => {
    const img = new Image();
    img.src = url;
    img.crossOrigin = "";
    img.onload = () => {
      console.log("加载完毕");
      resolve(img);
    };
  });
}
Promise.all([
  loadImg(
    "https://img.ljcdn.com/element-library/prod-eb48e4d2-9bb1-4997-b022-44bb719588f5.jpg"
  ).then((img) => {
    ctx1.drawImage(img, 0, 0, radius, radius);
  }),
  loadImg(
    "https://img.ljcdn.com/element-library/prod-84d85cbb-914d-4dea-bf1b-18e63241a29c.jpg"
  ).then((img) => {
    ctx2.drawImage(img, 0, 0, radius, radius);
  }),
]).then(() => {
  console.log("图像加载完毕");
  console.log("开始拼接图像");
  console.time("拼合图像");
  combiner.drawCanvas(ctx1, radius, radius, 0, 0);
  combiner.drawCanvas(ctx2, radius, radius, radius, 0);
  loadImg("./city.png").then((img) => {
    // combiner.drawCanvas(img, img.naturalWidth, img.naturalHeight, 0, 0, true);
    // combiner.download((gpu ? "[GPU]" : "[CPU]") + "编译_" + Date.now());
    const data = combiner.getFile();
    const url = URL.createObjectURL(data);
    document.getElementById("preview").src = url;
    console.timeEnd("拼合图像");
  });
});

// c1.toBlob((data) => {
//   const a = document.createElement("a");
//   a.href = URL.createObjectURL(data);
//   a.download = "原始.png";
//   a.click();
// });
